package model;

import java.util.TreeSet;

import dataLayer.DAOUser;

public class Users {

	private static Users instance = null;

	private TreeSet<User> userList = new TreeSet<User>();

	public Users() {
	
		userList = DAOUser.getInstance().loadallUser();
	}

	public boolean addUser(User u) {

		if (userList.add(u)) {
			DAOUser.getInstance();
			return true;
		}
		return false;
	}

	public TreeSet<User> getAllUsers() {
		return userList;
	}

	public void setAllUsers() {
		userList = DAOUser.getInstance().loadallUser();
	}

	public User getUser(User u) {
		String name = u.getUser_Name();
		for (User u1 : userList) {
			if (u1.getUser_Name() == name) {
				return u1;
			}
		}
		return null;
	}

	public void deleteUser(User u) {
		String name = u.getUser_Name();
		for (User u2 : userList) {
			if (name == u2.getUser_Name()) {
				userList.remove(u2);
				break;
			}
		}
	}

	public static Users getInstance() {
		if (instance == null) {
			instance = new Users();
		}
		return instance;

	}

}
